// login
window.onload = function(){
    // 封装 获取元素
    function $Key(getKey) {
        return document.querySelector(getKey)
    }
    $Key("#sub_btn").onclick = function () {
        let loginId = $Key("#loginId").value
        let loginPwd = $Key("#loginPwd").value

        // 获取的表单内容 通过 ajax 传给后端
        let xhr = new XMLHttpRequest()
        xhr.open("GET", `https://www.bingjs.com:8001/Admin/Login?loginId=${loginId}&loginPwd=${loginPwd}`)
        xhr.send()
        xhr.onreadystatechange = function () {
            if (xhr.readyState === 4 && xhr.status === 200) {
                let obj = JSON.parse(xhr.response)
                //obj.success ===> true / false ，请求成功
                if(obj.success){
                    location.href = "../html/mainPage.html"
                }else{
                    // obj.message 请求失败 给出的提示
                    alert(obj.message)
                }
            }
        }
    }
    $Key("#cancel_btn").onclick = function(){
        $Key("#loginId").value = ""
        $Key("#loginPwd").value = ""
        loginId=""
        loginPwd=""
    }
}